/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package classesInterface;

import classesBancodeDados.FichaLaudoAutorInternHosp;
import classesBancodeDados.Paciente;
import classesBancodeDados.Pessoa;
import classesJpa.FichaLaudoAutorInternHospJpaController;
import classesJpa.exceptions.NonexistentEntityException;
import classesMiolo.Formatador;
import classesMiolo.MapasPaciente;
import classesMiolo.ReverseMapper;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;

/**
 *
 * @author thiago
 */
public class TelaFichaLaudoSolicitacaoAutorizacao extends javax.swing.JFrame {

    /**
     * Creates new form LaudoSolicitacaoAutorizacao
     */
    private TelaFichaLaudoSolicitacaoAutorizacao() {
        initComponents();
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
    
    private static TelaFichaLaudoSolicitacaoAutorizacao uniqueInstance = null;
    
    public static TelaFichaLaudoSolicitacaoAutorizacao getInstance(){
        if(uniqueInstance == null){
            uniqueInstance = new TelaFichaLaudoSolicitacaoAutorizacao();
        }
        return uniqueInstance;
    }
    
    public void limpaCampos(){
        campoCEP.setText("");
        campoCidade.setText("");
        campoCnesExecutante.setText("");
        campoCnesSolicitante.setText("");
        campoEndereco.setText("");
        campoExecutante.setText("");
        campoMaeResp.setText("");
        campoNascimento.setText("");
        campoPaciente.setText("");
        campoProntuario.setText("");
        campoSolicitante.setText("");
        campoSus.setText("");
        campoTelefone.setText("");
        comboIBGE.setText("");
    }
    
    public void turnEditable(boolean editable){
        this.editable = editable;
        botaoSalvar.setEnabled(editable);
        campoCnesExecutante.setEditable(editable);
        campoCnesSolicitante.setEditable(editable); 
        campoExecutante.setEditable(editable);
        
        campoCEP.setEditable(false);
        campoCidade.setEditable(false);
        campoEndereco.setEditable(false);
        campoMaeResp.setEditable(false);
        campoNascimento.setEditable(false);
        campoPaciente.setEditable(false);
        campoProntuario.setEditable(false);
        campoSolicitante.setEditable(false);
        campoSus.setEditable(false);
        campoTelefone.setEditable(false);
        comboEstado.setEnabled(false);
        comboIBGE.setEnabled(false);     
    }
    
    public void preencherCampos(Paciente p, FichaLaudoAutorInternHosp laih){
        paciente = p;
        this.campoCEP.setText(p.getCep());
        this.campoCidade.setText(p.getCidade());
        this.campoCnesExecutante.setText(laih.getCnesEstabExecutante());
        this.campoCnesSolicitante.setText(laih.getCnesEstabSolicitante());
        this.campoEndereco.setText(p.getEndLogradouro() + ", " + p.getEndNumero() + ", " + p.getEndBairro());
        this.campoExecutante.setText(laih.getNomeEstabExecutante());
        this.campoMaeResp.setText(p.getNomeMae());
        this.campoNascimento.setText(p.getDataDeNascimento());
        this.campoPaciente.setText(p.getNome());
        this.campoProntuario.setText(laih.getNumeroProntuario());
        this.campoSolicitante.setText(laih.getNomeSolicitante());
        this.campoSus.setText(p.getSus());
        this.campoTelefone.setText(p.getTelefone());
        this.comboEstado.setSelectedItem(p.getEstado());
        this.comboIBGE.setText(p.getCodIbgeMunicipio());
        MapasPaciente mp = MapasPaciente.getInstance();
        this.comboSex.setSelectedItem(ReverseMapper.getKeyFromValue(mp.getSexo(), p.getSexo()));
    }
    
    public void salvar(){
        ficha.setCnesEstabExecutante(this.campoCnesExecutante.getText());
        ficha.setCnesEstabSolicitante(this.campoCnesSolicitante.getText());
        ficha.setNomeEstabExecutante(this.campoExecutante.getText());
        
        FichaLaudoAutorInternHospJpaController laic = new FichaLaudoAutorInternHospJpaController();
        try {
            laic.edit(ficha);
        } catch (NonexistentEntityException ex) {
            Logger.getLogger(TelaFichaLaudoSolicitacaoAutorizacao.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(TelaFichaLaudoSolicitacaoAutorizacao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        campoSolicitante = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        campoCnesSolicitante = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        campoExecutante = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        campoCnesExecutante = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        campoPaciente = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        campoProntuario = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        campoSus = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        campoNascimento = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        comboSex = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        campoMaeResp = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        campoTelefone = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        campoEndereco = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        campoCidade = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        comboEstado = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        comboIBGE = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        campoCEP = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        botaoSalvar = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setText("Laudo para Solicitação de Autorização de Internação Hospitalar ");

        jLabel2.setText("Nome do Estabelecimento Solicitante:");

        jLabel3.setText("CNES:");

        jLabel4.setText("Nome do Estabelecimento Executante:");

        jLabel5.setText("CNES:");

        jLabel6.setText("Identificação do Estabelecimento de Saúde");

        jLabel7.setText("Identificação do Paciente");

        jLabel8.setText("Nome do Paciente:");

        jLabel9.setText("Nº do Prontuário:");

        jLabel10.setText("Cartão Nacional de Saúde:");

        jLabel11.setText("Data de Nascimento:");

        campoNascimento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoNascimentoKeyPressed(evt);
            }
        });

        jLabel12.setText("Sexo:");

        comboSex.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Masculino", "Feminino" }));

        jLabel13.setText("Nome da Mãe ou Responsável:");

        jLabel14.setText("Telefone:");

        campoTelefone.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoTelefoneKeyPressed(evt);
            }
        });

        jLabel15.setText("Endereço:");

        jLabel16.setText("Cidade:");

        jLabel17.setText("Estado:");

        comboEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MS", "MT", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" }));
        comboEstado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboEstadoActionPerformed(evt);
            }
        });

        jLabel18.setText("Código IBGE do Município:");

        jLabel19.setText("CEP:");

        campoCEP.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoCEPKeyPressed(evt);
            }
        });

        jButton1.setText("Próximo >");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        botaoSalvar.setText("Salvar");
        botaoSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSalvarActionPerformed(evt);
            }
        });

        jButton3.setText("Cancelar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jSeparator1)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jSeparator2)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(campoSolicitante)
                                    .addComponent(campoExecutante, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoCnesSolicitante, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoCnesExecutante, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(17, 17, 17))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoProntuario))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel10)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoSus, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel11)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel13)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoMaeResp, javax.swing.GroupLayout.PREFERRED_SIZE, 384, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel14)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel12)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(comboSex, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addComponent(campoTelefone)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel15)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 387, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel16)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel18)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(comboIBGE, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel19)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoCEP)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboEstado, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(0, 3, Short.MAX_VALUE))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoSalvar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(5, 5, 5)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(campoSolicitante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(campoCnesSolicitante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(campoExecutante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(campoCnesExecutante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(campoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(campoProntuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(campoSus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(campoNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(comboSex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(campoMaeResp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(campoTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(campoEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16)
                    .addComponent(campoCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17)
                    .addComponent(comboEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(comboIBGE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(campoCEP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(botaoSalvar)
                    .addComponent(jButton3))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void comboEstadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboEstadoActionPerformed

    }//GEN-LAST:event_comboEstadoActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        TelaFichaLaudoSolicitacaoAutorizacao2.getInstance().setPessoa(pessoa);
        TelaFichaLaudoSolicitacaoAutorizacao2.getInstance().setFicha(ficha);
        TelaFichaLaudoSolicitacaoAutorizacao2.getInstance().preencherCampos(paciente, ficha);
        TelaFichaLaudoSolicitacaoAutorizacao2.getInstance().turnEditable(editable);
        this.setVisible(false);
        TelaFichaLaudoSolicitacaoAutorizacao2.getInstance().setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void botaoSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSalvarActionPerformed
        salvar();
    }//GEN-LAST:event_botaoSalvarActionPerformed

    private void campoTelefoneKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoTelefoneKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoTelefone.setText(Formatador.formataTelefone(campoTelefone.getText()));
        }
    }//GEN-LAST:event_campoTelefoneKeyPressed

    private void campoNascimentoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoNascimentoKeyPressed
        if(evt.getKeyChar() != '\b'){
            this.campoNascimento.setText(Formatador.formataData(this.campoNascimento.getText()));
        }
    }//GEN-LAST:event_campoNascimentoKeyPressed

    private void campoCEPKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoCEPKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoCEP.setText(Formatador.formataData(campoCEP.getText()));
        }
    }//GEN-LAST:event_campoCEPKeyPressed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        TelaFichaLaudoSolicitacaoAutorizacao.getInstance().limpaCampos();
        TelaFichaLaudoSolicitacaoAutorizacao2.getInstance().limpaCampos();
        TelaFichaLaudoSolicitacaoAutorizacao3.getInstance().limpaCampos();
        setVisible(false);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        TelaFichaLaudoSolicitacaoAutorizacao.getInstance().limpaCampos();
        TelaFichaLaudoSolicitacaoAutorizacao2.getInstance().limpaCampos();
        TelaFichaLaudoSolicitacaoAutorizacao3.getInstance().limpaCampos();
    }//GEN-LAST:event_formWindowClosing

    public FichaLaudoAutorInternHosp getFicha() {
        return ficha;
    }

    public void setFicha(FichaLaudoAutorInternHosp ficha) {
        this.ficha = ficha;
    }   

    public Pessoa getPessoa() {
        return pessoa;
    }

    public void setPessoa(Pessoa pessoa) {
        this.pessoa = pessoa;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaFichaLaudoSolicitacaoAutorizacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaFichaLaudoSolicitacaoAutorizacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaFichaLaudoSolicitacaoAutorizacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaFichaLaudoSolicitacaoAutorizacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                TelaFichaLaudoSolicitacaoAutorizacao.getInstance().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoSalvar;
    private javax.swing.JTextField campoCEP;
    private javax.swing.JTextField campoCidade;
    private javax.swing.JTextField campoCnesExecutante;
    private javax.swing.JTextField campoCnesSolicitante;
    private javax.swing.JTextField campoEndereco;
    private javax.swing.JTextField campoExecutante;
    private javax.swing.JTextField campoMaeResp;
    private javax.swing.JTextField campoNascimento;
    private javax.swing.JTextField campoPaciente;
    private javax.swing.JTextField campoProntuario;
    private javax.swing.JTextField campoSolicitante;
    private javax.swing.JTextField campoSus;
    private javax.swing.JTextField campoTelefone;
    private javax.swing.JComboBox comboEstado;
    private javax.swing.JTextField comboIBGE;
    private javax.swing.JComboBox comboSex;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    // End of variables declaration//GEN-END:variables
    private FichaLaudoAutorInternHosp ficha;
    private boolean editable;
    private Paciente paciente;
    private Pessoa pessoa;
}
